import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
 
public class MyFrame extends JFrame {
    
    private JButton button = new JButton("Press");
	private JTextField input = new JTextField("", 5);
	private JLabel label = new JLabel("Input:");
	private JRadioButton radio1 = new JRadioButton("Select this");
	private JRadioButton radio2 = new JRadioButton("Select that");
	private JCheckBox check = new JCheckBox("Check", false);
 
    class PushingListener implements ActionListener {
    	public void actionPerformed(ActionEvent e) {
    		JButton b=(JButton)e.getSource();    		
			String message = "";
			message += "Button was pressedn";
			message += "Text is " + input.getText() + "n";
			message += (radio1.isSelected()?"Radio #1":"Radio #2") + " is selectedn";
			message += "CheckBox is " + ((check.isSelected())?"checked":"unchecked");
			JOptionPane.showMessageDialog(null,
		    		message,
		    		"Output",
		    	    JOptionPane.PLAIN_MESSAGE);
		}
    }
 
    public MyFrame(String title){
        super(title);
        createGUI();
    }
 
    private void createGUI(){
    	this.setBounds(250,250,250,100);
	    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    Container container = this.getContentPane();
	    container.setLayout(new GridLayout(3,2,2,2));
	    container.add(label);
	    container.add(input);
	    ButtonGroup group = new ButtonGroup();
	    group.add(radio1);
	    group.add(radio2);
	    container.add(radio1);
	    radio1.setSelected(true);
	    container.add(radio2);
	    container.add(check);
	    button.addActionListener(new PushingListener());
	    container.add(button);
    }
}
